#!/usr/bin/perl -w
####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################
#BigDaddy Module: Ping (ICMP) Check
#Author: Duleepa Wijayawardhana
#Date: 26.03.2004
#=============================================================================#

use strict;
use Net::Ping;

my ($server) = @ARGV;
my $count=0;
my $bICMPAvail=0;
my $bTCPAvail=0;

#Check ICMP Proto
my $p = Net::Ping->new("icmp");

for (my $j=0; $j<5; $j++)
{
    if (!$p->ping($server, 5))
    {
        $count++;
    }
}

if ($count>3)
{
    $bICMPAvail=0;
}
else
{
    $bICMPAvail=1;
}


if ($bICMPAvail==1)
{
    print "1";
}
else
{
    print "0";
}
